/*
 * @lc app=leetcode.cn id=24 lang=golang
 *
 * [24] 两两交换链表中的节点
 */

// @lc code=start
/**
 * Definition for singly-linked list.
 * type ListNode struct {
 *     Val int
 *     Next *ListNode
 * }
 */
func swapPairs(head *ListNode) *ListNode {
	if head == nil || head.Next == nil {
		return head
	}

	dummyNode := &ListNode{Next: head}
	prev := dummyNode
	current := dummyNode
	next := current.Next

	for current != nil && next != nil {
		prev.Next = next
		current.Next = next.Next
		next.Next = current
		prev = current
		current = prev.Next
		next = current.Next
	}

	return dummyNode.Next
}

// @lc code=end

